home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / share / ewl / examples / ewl_tree_test.c < prev   
C/C++ Source or Header  |  2006-01-09  |  4KB  |  140 lines

  1. #include "ewl_test.h"
  2.  
  3. #define ROWS 50
  4. #define COLS 4
  5. #define NEST 3
  6.  
  7. static Ewl_Widget *tree_button;
  8.  
  9. static void
  10. __destroy_tree_test_window(Ewl_Widget * w, void *ev_data __UNUSED__,
  11.                  void *user_data __UNUSED__)
  12. {
  13.     ewl_widget_destroy(w);
  14.     ewl_callback_append(tree_button, EWL_CALLBACK_CLICKED,
  15.                 __create_tree_test_window, NULL);
  16. }
  17.  
  18. static void
  19. __get_rows(Ewl_Widget *w __UNUSED__, void *ev_data __UNUSED__,
  20.                     void *user_data)
  21. {
  22.     Ecore_List *selected;
  23.     Ewl_Tree *tree;
  24.     
  25.     tree = user_data;
  26.     selected = ewl_tree_selected_get(tree);
  27.     printf("Selected %d rows\n", ecore_list_nodes(selected));
  28. }
  29.  
  30. void
  31. __create_tree_test_window(Ewl_Widget * w, void *ev_data __UNUSED__,
  32.                 void *user_data __UNUSED__)
  33. {
  34.     int row, col;
  35.     char buf[PATH_MAX];
  36.     char *headers[COLS];
  37.     char *entries[COLS];
  38.     Ewl_Widget *tree_win;
  39.     Ewl_Widget *tree;
  40.     Ewl_Widget *prow = NULL;
  41.     Ewl_Widget *box;
  42.     Ewl_Widget *hbox;
  43.     Ewl_Widget *button;
  44.  
  45.     tree_button = w;
  46.  
  47.     tree_win = ewl_window_new();
  48.     ewl_object_fill_policy_set(EWL_OBJECT(tree_win), EWL_FLAG_FILL_ALL);
  49.     ewl_window_title_set(EWL_WINDOW(tree_win), "Tree Test");
  50.     ewl_window_name_set(EWL_WINDOW(tree_win), "EWL Test Application");
  51.     ewl_window_class_set(EWL_WINDOW(tree_win), "EFL Test Application");
  52.     /* ewl_object_set_maximum_size(EWL_OBJECT(tree_win), 400, 400); */
  53.     ewl_object_size_request(EWL_OBJECT(tree_win), 400, 200);
  54.  
  55.     if (w) {
  56.         ewl_callback_del(w, EWL_CALLBACK_CLICKED,
  57.                              __create_tree_test_window);
  58.         ewl_callback_append(tree_win, EWL_CALLBACK_DELETE_WINDOW,
  59.                 __destroy_tree_test_window, NULL);
  60.     } else
  61.         ewl_callback_append(tree_win, EWL_CALLBACK_DELETE_WINDOW,
  62.                         __close_main_window, NULL);
  63.     ewl_widget_show(tree_win);
  64.  
  65.     box = ewl_vbox_new();
  66.     ewl_container_child_append(EWL_CONTAINER(tree_win), box);
  67.     ewl_box_homogeneous_set(EWL_BOX(box), FALSE);
  68.     ewl_object_fill_policy_set(EWL_OBJECT(box), EWL_FLAG_FILL_ALL);
  69.     ewl_widget_show(box);
  70.  
  71.     hbox = ewl_hbox_new();
  72.     ewl_container_child_append(EWL_CONTAINER(box), hbox);
  73.     ewl_object_fill_policy_set(EWL_OBJECT(hbox), EWL_FLAG_FILL_SHRINK |
  74.                             EWL_FLAG_FILL_HFILL);
  75.     ewl_widget_show(hbox);
  76.  
  77.     /*
  78.      * Create the tree first to allow for attaching to button callbacks
  79.      */
  80.     tree = ewl_tree_new(COLS);
  81.  
  82.     /*
  83.      * Create buttons for retrieving tree info
  84.      */
  85.     button = ewl_button_new();
  86.     ewl_button_label_set(EWL_BUTTON(button), "Number of selected rows");
  87.     ewl_container_child_append(EWL_CONTAINER(hbox), button);
  88.     ewl_object_fill_policy_set(EWL_OBJECT(button), EWL_FLAG_FILL_HFILL);
  89.     ewl_callback_append(button, EWL_CALLBACK_CLICKED, __get_rows, tree);
  90.     ewl_widget_show(button);
  91.  
  92.     button = ewl_button_new();
  93.     ewl_button_label_set(EWL_BUTTON(button), "Clear selection");
  94.     ewl_container_child_append(EWL_CONTAINER(hbox), button);
  95.     ewl_object_fill_policy_set(EWL_OBJECT(button), EWL_FLAG_FILL_HFILL);
  96.     ewl_callback_append(button, EWL_CALLBACK_CLICKED, __get_rows, tree);
  97.     ewl_widget_show(button);
  98.  
  99.     for (col = 0; col < COLS; col++) {
  100.         snprintf(buf, PATH_MAX, "Column %d", col);
  101.         headers[col] = strdup(buf);
  102.     }
  103.  
  104.     ewl_container_child_append(EWL_CONTAINER(box), tree);
  105.     ewl_tree_headers_set(EWL_TREE(tree), headers);
  106.     ewl_widget_show(tree);
  107.  
  108.     memset(entries, 0, COLS * sizeof(char *));
  109.  
  110.     for (row = 0; row < ROWS; row++) {
  111.  
  112.         /*
  113.          * Build the array of entries.
  114.          */
  115.         for (col = 0; col < COLS; col++) {
  116.             snprintf(buf, 1024, "Row %d Col %d", row, col);
  117.             IF_FREE(entries[col]);
  118.             entries[col] = strdup(buf);
  119.         }
  120.  
  121.         if (row % NEST == 0)
  122.             prow = ewl_tree_text_row_add(EWL_TREE(tree), NULL,
  123.                     entries);
  124.         else
  125.             prow = ewl_tree_text_row_add(EWL_TREE(tree),
  126.                     EWL_ROW(prow), entries);
  127.  
  128.         for (col = 0; col < COLS; col++) {
  129.             IF_FREE(entries[col]);
  130.         }
  131.     }
  132.  
  133.     for (col = 0; col < COLS; col++) {
  134.         IF_FREE(headers[col]);
  135.     }
  136.  
  137.     printf("Tree setup complete!!!\n");
  138. }
  139.  
  140.